# archer
# political advan, disadvan, and the demand for partisan news
# replication file - bootstraps

##############
# bootstrap. #
##############
library(foreign)

circs<-read.csv("all_circulations_replication.csv", as.is=TRUE)

#for 1932-2004
circs <- circs[2:20,]
View(circs)

circs$gopmargpct <- ((circs$gopvote-circs$demvote)/circs$totalvotes)*100
circs$totalcircs <- circs$circsumR+circs$circsumD+circs$circsumI+circs$circsumN
circs$didrpct <- (((circs$circsumR-circs$circsumRlast)-(circs$circsumD-circs$circsumDlast))/circs$totalcircs)*100

boot_coef <- matrix(NA, nrow=250, ncol=2)

for(i in 1:250){
  rowindx <- sample(seq(1,nrow(circs)), size=nrow(circs), replace=TRUE)
  xboot <- circs[rowindx,]
  xboot <- as.data.frame(xboot)
  model1 <- lm(didrpct ~ gopmargpct, data=xboot)
  boot_coef[i,] <- model1$coefficients}

apply(boot_coef,2, mean)

quantile(boot_coef[,2], c(0.025, 0.975))

quantile(boot_coef[,1], c(0.025, 0.975))

